home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / clck.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  4KB  |  179 lines

  1. /***   [clck.c]
  2. *
  3. *    時計ウィンドウ 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <stdio.h>
  10. #include <math.h>
  11. #include <bios.h>
  12. #include "graph.h"
  13. #include "mos.h"
  14. #include "window.h"
  15. #include "icn.h"
  16. #include "others.h"
  17.  
  18. #define WH_CAN        1
  19. #define WH_TITLE    2
  20. #define WH_OTHER    0
  21.  
  22. extern int    PAL_Black;
  23. static int    wx, wy;
  24. static int    ptime[3];
  25. static float    pcord[6];
  26.  
  27. extern void    segpatch(void);
  28. static void    Draw_window(void);
  29. static int    Where(int, int);
  30. static void    clock(void);
  31. static void    cal(int, int);
  32.  
  33. void WIND_clock(void) {
  34.     int        ret = 0, i;
  35.     struct RECT    a, b;
  36.     
  37.     wx = 235;
  38.     wy = 145;
  39.     a.x1 = 319;    a.y1 = 259;
  40.     a.x2 = 320;    a.y2 = 260;
  41.     b.x1 = wx;    b.y1 = wy;
  42.     b.x2 = wx + 169;    b.y2 = wy + 190;
  43.     afterImage(&a, &b);
  44.     
  45.     for (i = 0; i < 3; ptime[i++] = -1);
  46.     for (i = 0; i < 6; pcord[i++] = 0);
  47.     Draw_window();
  48.     while (!ret) {
  49.         char    mb;
  50.         int        mx, my, wh;
  51.         
  52.         CLOCK(0);
  53.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1)) {
  54.             clock();
  55.             continue;
  56.         }
  57.         
  58.         if ((wh = Where(mx, my)) == WH_CAN) {
  59.             if (Button(wx + 6, wy + 6, wx + 25, wy + 25))
  60.                 ret = 1;
  61.         } else if (wh == WH_TITLE) {
  62.             struct RECT    s, w;
  63.             
  64.             w.x1 = wx;    w.y1 = wy;
  65.             w.x2 = wx + 169;    w.y2 = wy + 190;
  66.             s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  67.             if (dragWindow(mx, my, &w, &s, 0, 0)) {
  68.                 wx = w.x1;    wy = w.y1;
  69.                 MOS_disp(0);
  70.                 EGB_cls(0);
  71.                 MOS_disp(1);
  72.                 Draw_window();
  73.                 for (i = 0; i < 3; ptime[i++] = -1);
  74.                 for (i = 0; i < 6; pcord[i++] = 0);
  75.             }
  76.         } else {
  77.             while (MOS_rdpos(&mb, &mx, &my), mb & 1)
  78.                 clock();
  79.         }
  80.     }
  81.     
  82.     return;
  83. }
  84.  
  85. static void Draw_window(void) {
  86.     short    cir[3];
  87.     struct opnwin_t    opw;
  88.     
  89.     opw.title = "Clock";
  90.     opw.x1 = wx;
  91.     opw.y1 = wy;
  92.     opw.x2 = opw.x1 + 169;
  93.     opw.y2 = opw.y1 + 190;
  94.     opw.shdw = 1;
  95.     opw.canb = 1;
  96.     opw.nopt = 0;
  97.     opw.wopt = NULL;
  98.     opw.expb = 0;
  99.     opw.ord = 0;
  100.     MOS_disp(0);
  101.     drawWindow(&opw);
  102.     
  103.     EGB_color(EGB_work, EGB_COL_FORE, PAL_Black);
  104.     EGB_color(EGB_work, EGB_COL_PAINT, 15);
  105.     EGB_paintMode(EGB_work, 0x022);
  106.     
  107.     EGB_pen(EGB_work, 0);
  108.     EGB_penSize(EGB_work, 7);
  109.     cir[0] = wx + 85;
  110.     cir[1] = wy + 106;
  111.     cir[2] = 65;
  112.     EGB_circle(EGB_work, (char *)cir);
  113.     EGB_penSize(EGB_work, 1);
  114.     MOS_disp(1);
  115. }
  116.  
  117. static int Where(int x, int y) {
  118.     int        ret;
  119.     
  120.     x -= wx;
  121.     y -= wy;
  122.     if (5 < x && x < 26 && 5 < y && y < 26)
  123.         ret = WH_CAN;
  124.     else if (26 < x && x < 164 && 5 < y && y < 26)
  125.         ret = WH_TITLE;
  126.     else
  127.         ret = WH_OTHER;
  128.     
  129.     return ret;
  130. }
  131.  
  132. static void clock(void) {
  133.     struct calender_t    a;
  134.     
  135.     _bios_timeofday(_TIME_GETCLOCK, &a);
  136.     if (a.second == ptime[2])
  137.         return;
  138.     
  139.     MOS_disp(0);
  140.     cal(2, a.second);
  141.     cal(1, a.minute);
  142.     cal(0, a.hour * 60 + a.minute);
  143.     MOS_disp(1);
  144. }
  145.  
  146. #define PI    (3.141592654)
  147. static void cal(int mode, int t) {
  148.     int        rr;
  149.     float    r, x, y;
  150.     
  151.     switch (mode) {
  152.         case 0:
  153.             EGB_penSize(EGB_work, 7);
  154.             rr = 40;
  155.             break;
  156.         case 1:
  157.             EGB_penSize(EGB_work, 5);
  158.             rr = 55;
  159.             break;
  160.         default:
  161.             EGB_penSize(EGB_work, 1);
  162.             rr = 55;
  163.             break;
  164.     }
  165.     segpatch();        /* Segment Register Settings */
  166.     r = PI / 2.0 - (mode == 0 ? (t % 720) / 720.0 : t / 60.0) * 2.0 * PI;
  167.     x = rr * cos(r);
  168.     y = rr * sin(r);
  169.     if (ptime[mode] != t) {
  170.         EGB_line(wx + 85, wy + 106, wx + 85 + pcord[mode * 2], wy + 106 - pcord[mode * 2 + 1], 15);
  171.         ptime[mode] = t;
  172.         pcord[mode * 2] = x;
  173.         pcord[mode * 2 + 1] = y;
  174.     }
  175.     EGB_line(wx + 85, wy + 106, wx + 85 + x, wy + 106 - y, PAL_Black);
  176.     EGB_penSize(EGB_work, 1);
  177. }
  178. #undef PI
  179.